home *** CD-ROM | disk | FTP | other *** search
/ Chip 2006 July / CHIP 2006-07.2.iso / program / web_gelistirme / easyphp1-7_setup.exe / {app} / phpmyadmin / tbl_rename.php < prev    next >
Encoding:
PHP Script  |  2003-09-07  |  3.8 KB  |  110 lines

  1. <?php
  2. /* $Id: tbl_rename.php,v 1.26 2003/08/05 17:12:48 nijel Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5.  
  6. /**
  7.  * Gets some core libraries
  8.  */
  9. require('./libraries/grab_globals.lib.php');
  10. $js_to_run = 'functions.js';
  11. require('./libraries/common.lib.php');
  12.  
  13. PMA_checkParameters(array('db','table'));
  14.  
  15. /**
  16.  * Defines the url to return to in case of error in a sql statement
  17.  */
  18. $err_url = 'tbl_properties.php?' . PMA_generate_common_url($db, $table);
  19.  
  20.  
  21. /**
  22.  * A new name has been submitted -> do the work
  23.  */
  24. if (isset($new_name) && trim($new_name) != '') {
  25.     $old_name     = $table;
  26.     $table        = $new_name;
  27.  
  28.     // Ensure the target is valid
  29.     if (count($dblist) > 0 && PMA_isInto($db, $dblist) == -1) {
  30.         exit();
  31.     }
  32.     if (PMA_MYSQL_INT_VERSION < 32306) {
  33.         PMA_checkReservedWords($new_name, $err_url);
  34.     }
  35.  
  36.     include('./header.inc.php');
  37.     PMA_mysql_select_db($db);
  38.     $sql_query = 'ALTER TABLE ' . PMA_backquote($old_name) . ' RENAME ' . PMA_backquote($new_name);
  39.     $result    = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url);
  40.     $message   = sprintf($strRenameTableOK, htmlspecialchars($old_name), htmlspecialchars($table));
  41.     $reload    = 1;
  42.  
  43.     // garvin: Move old entries from comments to new table
  44.     include('./libraries/relation.lib.php');
  45.     $cfgRelation = PMA_getRelationsParam();
  46.     if ($cfgRelation['commwork']) {
  47.         $remove_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_info'])
  48.                       . ' SET     table_name = \'' . PMA_sqlAddslashes($table) . '\''
  49.                       . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\''
  50.                       . ' AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\'';
  51.         $rmv_rs    = PMA_query_as_cu($remove_query);
  52.         unset($rmv_query);
  53.     }
  54.  
  55.     if ($cfgRelation['displaywork']) {
  56.         $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_info'])
  57.                         . ' SET     table_name = \'' . PMA_sqlAddslashes($table) . '\''
  58.                         . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\''
  59.                         . ' AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\'';
  60.         $tb_rs    = PMA_query_as_cu($table_query);
  61.         unset($table_query);
  62.         unset($tb_rs);
  63.     }
  64.  
  65.     if ($cfgRelation['relwork']) {
  66.         $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation'])
  67.                         . ' SET     foreign_table = \'' . PMA_sqlAddslashes($table) . '\''
  68.                         . ' WHERE foreign_db  = \'' . PMA_sqlAddslashes($db) . '\''
  69.                         . ' AND foreign_table = \'' . PMA_sqlAddslashes($old_name) . '\'';
  70.         $tb_rs    = PMA_query_as_cu($table_query);
  71.         unset($table_query);
  72.         unset($tb_rs);
  73.  
  74.         $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation'])
  75.                         . ' SET     master_table = \'' . PMA_sqlAddslashes($table) . '\''
  76.                         . ' WHERE master_db  = \'' . PMA_sqlAddslashes($db) . '\''
  77.                         . ' AND master_table = \'' . PMA_sqlAddslashes($old_name) . '\'';
  78.         $tb_rs    = PMA_query_as_cu($table_query);
  79.         unset($table_query);
  80.         unset($tb_rs);
  81.     }
  82.     
  83.     if ($cfgRelation['pdfwork']) {
  84.         $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_coords'])
  85.                         . ' SET     table_name = \'' . PMA_sqlAddslashes($table) . '\''
  86.                         . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\''
  87.                         . ' AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\'';
  88.         $tb_rs    = PMA_query_as_cu($table_query);
  89.         unset($table_query);
  90.         unset($tb_rs);
  91.     }
  92.  
  93. }
  94.  
  95.  
  96. /**
  97.  * No new name for the table!
  98.  */
  99. else {
  100.     include('./header.inc.php');
  101.     PMA_mysqlDie($strTableEmpty, '', '', $err_url);
  102. }
  103.  
  104.  
  105. /**
  106.  * Back to the calling script
  107.  */
  108. require('./tbl_properties.php');
  109. ?>
  110.